package com.itheima.jobs;

import cn.hutool.core.collection.CollectionUtil;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author nglsk
 * @version v1.0
 * @date 2019/11/24 18:01
 * @description TODO
 **/

@Component
public class ClearImages {

    @Autowired
    JedisPool jedisPool;
    public void run() {
//
        Jedis resource = jedisPool.getResource();
        Set<String> sdiff = resource.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (CollectionUtil.isNotEmpty(sdiff)) {
            for (String imgName : sdiff) {
                QiNiuUtil.delete(imgName);
                resource.srem(RedisConstant.SETMEAL_PIC_RESOURCES, imgName);
            }
        }
        resource.close();
    }
}
